<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: VListMenuPortlet.php 453 2011-01-07 13:41:08Z steen.rabol $
 * @package Pradoportal.Porttlets.LanguagePortlet
 *
 */

Prado::using('Application.Portlets.Portlet');
Prado::using('Application.Portlets.VListMenuPortlet.Common.VListMenuPortletRecord');
Prado::using('Application.Common.Data.PortalSiteMenuRecord');
Prado::using('Application.Common.Data.PortalSiteMenuItemRecord');

class VListMenuPortlet extends Portlet
{
    protected function getPropertyName()
	{
		return 'prop_' . get_class() . '_' . $this->Service->RequestedPagePath . '_' . $this->Parameters['id'];
	}

	protected function getConfigName()
	{
		return get_class() . '_' . $this->Parameters['id'];
	}

	public function  onLoad($param)
	{
		parent::onLoad($param);

		$cValues = Prado::unserialize($this->ConfigRecord->value);
		if($cValues && is_array($cValues) && count($cValues))
		{
			if(isset($cValues['sitemenuid']))
			{
				$SiteMenuId	= TPropertyValue::ensureInteger($cValues['sitemenuid']);
			}
			else
			{
				$SiteMenuId	= -1;
			}

			if(isset($cValues['menuheader']))
			{
				$MenuHeader	= TPropertyValue::ensureString($cValues['menuheader']);
			}
			else
			{
				$MenuHeader	= '';
			}
		}

		if($this->CustomProperties)
		{
			if(isset($this->CustomProperties['menucss']) && $this->CustomProperties['menucss'] != '')
				$menucss = $this->CustomProperties['menucss'];
			else
				$menucss	='vlistmenu';
		}
		else
		{
			$menucss = 'vlistmenu';
		}

		if($MenuHeader != '')
		{
			//TODO - get properties!
			$this->tlMenuHeader->Text		= "<h3 class=\"headerbar\">". $MenuHeader . "</h3>";
		}

		$this->pnlVListManu->CssClass	= $menucss;
		$this->lstMenu->CssClass		= $menucss;
		
		if($SiteMenuId != -1)
		{
			$SiteMenu	= PortalSiteMenuRecord::finder()->findById($SiteMenuId);
			if($SiteMenu)
			{
				$SiteMenuItems = PortalSiteMenuItemRecord::finder()->findAllBysmid($SiteMenuId);
				if($SiteMenuItems)
				{
					foreach($SiteMenuItems as $SiteMenuItem)
					{
						$selected = false; //TODO - set active...
						$this->lstMenu->Items[] = new TListItem($SiteMenuItem->title, $this->Service->constructUrl($SiteMenuItem->page), true, $selected);
					}
				}
			}
		}
	}
}
?>
